/**
 * Created by DELL on 2017/4/18.
 */
const mymerge = function (arr) {
    function merge(left, right) {
        //当arr长度小于一定值的时候,可以使用插入或者选择来帮助排序
        if(left[left.length-1]<right[0]){
            //如果左右数组已经排好顺序了,不用归并了
            return left.concat(right);
        };
        var result = [];
        while (left.length > 0 && right.length > 0) {
            if (left[0] < right[0]) {
                result.push(left.shift())
            } else {
                result.push(right.shift())
            }
        }
        ;
        return result.concat(left, right);
    };
    var mergeSort = function (arr1) {
        if (arr1.length === 1) return arr1;
        var mid = Math.floor(arr1.length / 2);
        var left = arr1.slice(0, mid);
        var right = arr1.slice(mid);
            return merge(mergeSort(left), mergeSort(right));

    };
    console.log('归并排序:');
};

module.exports = mymerge;

